Skip to content

Conversation

HeahDude
Copy link

@HeahDude HeahDude commented May 21, 2022

While trying to improve some configuration blocks in Symfony docs, I found out that it was not possible to use constants for the verbosity levels of the console handler.
I think it's missing now that we tend to spread PHP config files such as config/packages/monolog.php.

Before this patch one gets the following exception:

Symfony\Component\Config\Definition\Exception\InvalidConfigurationException: Unrecognized options "32, 128" under "monolog.handlers.console.verbosity_levels". Available options are "VERBOSITY_DEBUG", "VERBOSITY_NORMAL", "VERBOSITY_QUIET", "VERBOSITY_VERBOSE", "VERBOSITY_VERY_VERBOSE".

Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻 for allowing constant instead of "magic" strings.

There is a 2nd transformation of constant name to constant value in the config validation callback. All that may be simplified by converting to const values in the normalization.

The only drawback is that there will be int displayed instead of constant names when using debug:config.

@@ -1015,10 +1016,13 @@ private function addVerbosityLevelSection(ArrayNodeDefinition $handerNode)
->then(function ($v) {
$map = [];
$verbosities = ['VERBOSITY_QUIET', 'VERBOSITY_NORMAL', 'VERBOSITY_VERBOSE', 'VERBOSITY_VERY_VERBOSE', 'VERBOSITY_DEBUG'];
// allow numeric indexed array with ascendning verbosity and lowercase names of the constants
$verbosityConstants = [OutputInterface::VERBOSITY_QUIET, OutputInterface::VERBOSITY_NORMAL, OutputInterface::VERBOSITY_VERBOSE, OutputInterface::VERBOSITY_VERY_VERBOSE, OutputInterface::VERBOSITY_DEBUG];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The array should look like [OutputInterface::VERBOSITY_QUIET => 'VERBOSITY_QUIET', ...] to remove the array_search and make the code more readable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can make the code a little clearer with this changes: HeahDude#1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants